<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>修改密码</title>
  <#include "/include/layui-top.html">
</head>
<body>
          
              
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
  <legend>修改密码（用户）</legend>
</fieldset>
 
<form id="passwdForm" class="layui-form" action="javascript:void(0);">
  
  <div class="layui-form-item">
    <input type="hidden" name="userId" value="<@shiro.principal property="id"/>">
    <label class="layui-form-label">原密码</label>
    <div class="layui-input-inline">
      <input type="password" name="origPasswd" lay-verify="pass" placeholder="请输入密码" autocomplete="off" class="layui-input">
    </div>
    <div class="layui-form-mid layui-word-aux">请填写5到20位密码</div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">新密码</label>
    <div class="layui-input-inline">
      <input type="password" id="newpasswd" lay-verify="pass" placeholder="请输入密码" autocomplete="off" class="layui-input">
    </div>
    <div class="layui-form-mid layui-word-aux">请填写5到20位密码</div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">重复密码</label>
    <div class="layui-input-inline">
      <input type="password" name="newPasswd" lay-verify="repass" placeholder="请输入密码" autocomplete="off" class="layui-input">
    </div>
    <div class="layui-form-mid layui-word-aux">请填写5到20位密码</div>
  </div>
  
  <div class="layui-form-item">
    <div class="layui-input-block">
      <button type="button" class="layui-btn" lay-submit lay-filter="changePasswdAction">立即修改</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
</form>

<#include "/include/layui-end.html">
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
layui.use(['form', 'layedit', 'laydate'], function(){
  var $ = layui.$,
  form = layui.form,
  layedit = layui.layedit,
  layer = layui.layer;

 
  //自定义验证规则
  form.verify({
    pass: [
      /^[\S]{5,20}$/
      ,'密码必须5到20位，且不能出现空格'
    ],
    repass: function(value){
    	var pass = $("#newpasswd").val();
    	if(pass != value) {
   			return '两次输入的密码不一致';
   		}
    },
    content: function(value){
      layedit.sync(editIndex);
    }
  });
  
  
  //监听提交
  form.on('submit(changePasswdAction)', function(data){
	  $.ajax({
		    type: 'POST',
		    url: '/user/password/change_passwd',
		    data: data.field,
		    success: function (data) {
		        if(data.success){
		    	    layer.msg(data.message);
		    	    $('#passwdForm')[0].reset();
		        }else{
		            layer.msg(data.message,{icon: 5,anim: 6,time: 0,btn:['确定']});
		        }
		    },
		    error: function(data) {
		        layer.msg(data.responseJSON.message,{icon: 5,anim: 6,time: 0,btn:['确定']});
		    },
		    dataType: "json"
		});
    /* layer.alert(JSON.stringify(data.field), {
      title: '最终的提交信息'
    }) */
    return false;
  });
 
});
</script>

</body>
</html>